<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- window.qdoc -->
  <title>Qt Quick 示例 - Window and Screen | Qt Quick 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtquick-index.html">Qt Quick 模块</a></td><td >Qt Quick 示例 - 窗口和屏幕</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtquick-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">目录</a></h3>
<ul>
<li class="level1"><a href="#running-the-example">运行该示例</a></li>
<li class="level1"><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtquick/qtquick-window-example.html#window-implementation">窗口实现</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Qt Quick 示例 - 窗口和屏幕</h1>
<span class="subtitle"></span>
<!-- $$$window-brief -->
<p>此示例演示 QML 中的 Window 和 Screen 类型。</p>
<!-- @@@window -->
<!-- $$$window-description -->
<div class="descr"> <a name="details"></a>
<p class="centerAlign"><img src="images/qml-window-example.png" alt="" /></p><p><i>窗口和屏幕</i>显示如何：</p>
<ul>
<li>在 QML 中创建一个窗口</li>
<li>控制其<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtgui/qwindow.html#visibility-prop">可见性</a></li>
<li>在应用程序启动期间显示启动画面</li>
<li>访问<a href="qml-qtquick-window-screen.html">Screen</a>的属性 </li>
</ul>
<p>它还演示了如何将 QML 打包到<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtcore/resources.html">资源</a>中并提供一个<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtdoc/appicon.html">图标</a>来创建一个独立的 QML 桌面应用程序。</p>
<a name="running-the-example"></a>
<h2 id="running-the-example">运行该示例</h2>
<p>要从 <a href="http://doc.qt.io/qtcreator/index.html">Qt Creator</a>运行示例，请打开<b>欢迎</b> 模式并从 <b>示例</b>中选择示例。有关更多信息，请访问<a href="http://doc.qt.io/qtcreator/creator-build-example-application.html">构建和运行示例</a>。</p>
<a name="window-implementation"></a>
<h2 id="window-implementation">窗口实现</h2>
<p>可以使用<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtcore/qt.html#WindowType-enum">Qt.SplashScreen</a>标志创建启动画面，并且应该是<a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtcore/qt.html#WindowModality-enum">ApplicationModal</a>以防止与主窗口交互。如果启动窗口也是透明的，并且显示部分透明的图像，那么它将看起来像一个成形的窗口。</p>
<pre class="qml">

  <span class="type"><a href="qml-qtquick-window-window.html">Window</a></span> {
      <span class="name">id</span>: <span class="name">splash</span>
      <span class="name">color</span>: <span class="string">&quot;transparent&quot;</span>
      <span class="name">title</span>: <span class="string">&quot;Splash Window&quot;</span>
      <span class="name">modality</span>: <span class="name">Qt</span>.<span class="name">ApplicationModal</span>
      <span class="name">flags</span>: <span class="name">Qt</span>.<span class="name">SplashScreen</span>
      property <span class="type"><a href="../qtqml/qml-int.html">int</a></span> <span class="name">timeoutInterval</span>: <span class="number">2000</span>
      signal <span class="type">timeout</span>

</pre>
<p>在此示例中，<a href="../qtqml/qml-qtqml-timer.html">Timer</a>将自动关闭启动画面，但在实际应用程序中，您可能希望连接到来自应用程序逻辑的信号以在初始化完成时隐藏启动画面。</p>
<pre class="qml">

  <span class="type"><a href="../qtqml/qml-qtqml-timer.html">Timer</a></span> {
      <span class="name">interval</span>: <span class="name">timeoutInterval</span>; <span class="name">running</span>: <span class="number">true</span>; <span class="name">repeat</span>: <span class="number">false</span>
      <span class="name">onTriggered</span>: {
          <span class="name">visible</span> <span class="operator">=</span> <span class="number">false</span>
          <span class="name">splash</span>.<span class="name">timeout</span>()
      }
  }

</pre>
<p>此示例中的主窗口是控制窗口，带有一些按钮和复选框来控制和提供有关辅助窗口状态的反馈。每个复选框都有一个绑定到它正在显示其状态的属性，以及一个用于更改状态的 onClicked 处理程序。这是创建双向绑定同时避免绑定循环的典型模式。</p>
<pre class="qml">

  <span class="type">Shared</span>.CheckBox {
      <span class="name">text</span>: <span class="string">&quot;Windowed&quot;</span>
      <span class="name">height</span>: <span class="name">showButton</span>.<span class="name">height</span>
      <span class="name">width</span>: <span class="name">col</span>.<span class="name">cellWidth</span>
      Binding on <span class="name">checked</span> { <span class="name">value</span>: <span class="name">testWindow</span>.<span class="name">visibility</span> <span class="operator">===</span> <span class="name">Window</span>.<span class="name">Windowed</span> }
      <span class="name">onClicked</span>: <span class="name">testWindow</span>.<span class="name">visibility</span> <span class="operator">=</span> <span class="name">Window</span>.<span class="name">Windowed</span>
  }

</pre>
<p><a href="file:///E:/WLL/work/Qt5.12-Document-Trans-in-Chinese/qtquick/qml-qtquick-window-screen.html">Screen</a>有几个属性，这些属性通常对需要在屏幕方向改变时旋转某些内容、在屏幕上定位窗口或将实际单位转换为逻辑像素单位的应用程序很有用。CurrentScreen.qml（在 window.qml 中内联显示，或者可以使用 qmlscene 自行运行）仅显示属性值，而初始屏幕使用它们将窗口居中显示在屏幕上。</p>
<pre class="qml">

      <span class="name">x</span>: (<span class="name">Screen</span>.<span class="name">width</span> <span class="operator">-</span> <span class="name">splashImage</span>.<span class="name">width</span>) <span class="operator">/</span> <span class="number">2</span>
      <span class="name">y</span>: (<span class="name">Screen</span>.<span class="name">height</span> <span class="operator">-</span> <span class="name">splashImage</span>.<span class="name">height</span>) <span class="operator">/</span> <span class="number">2</span>

</pre>
<p>如果一个窗口嵌套在一个<a href="qml-qtquick-item.html">Item</a>或另一个<a href="qml-qtquick-window-window.html">Window</a>中，内部窗口对外部窗口来说就变成了瞬态窗口(更多的解释请参见<a href="qml-qtquick-window-window.html">Window</a>)。但是，如果您希望将多个顶级窗口作为不相关的对等点创建，您可以在一个非可视的<a href="../qtqml/qml-qtqml-qtobject.html">QtObject</a>根项中创建它们，就像本例所做的那样。</p>
<p>文件：</p>
<ul>
<li><a href="qtquick-window-allscreens-qml.html">window/AllScreens.qml</a></li>
<li><a href="qtquick-window-currentscreen-qml.html">window/CurrentScreen.qml</a></li>
<li><a href="qtquick-window-splash-qml.html">window/Splash.qml</a></li>
<li><a href="qtquick-window-main-cpp.html">window/main.cpp</a></li>
<li><a href="qtquick-window-resources-icon-svg.html">window/resources/icon.svg</a></li>
<li><a href="qtquick-window-window-pro.html">window/window.pro</a></li>
<li><a href="qtquick-window-window-qml.html">window/window.qml</a></li>
<li><a href="qtquick-window-window-qrc.html">window/window.qrc</a></li>
</ul>
<p>图片：</p>
<ul>
<li><a href="images/used-in-examples/window/resources/icon64.png">window/resources/icon64.png</a></li>
</ul>
</div>
<!-- @@@window -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
